//
//  BSPayResultViewController.m
//  BeleireaShop
//
//  Created by imac on 2019/10/24.
//  Copyright © 2019 imac. All rights reserved.
//

#import "BSPayResultViewController.h"
@interface BSPayResultViewController ()

@end

@implementation BSPayResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"确认结果";
    [self configWaitResultView];
    [self send_confim_request];

   
    // Do any additional setup after loading the view.
}
#pragma mark --configSubView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(24, 50, UISCREEN_WIDTH - 48, 207)];
    whiteView.backgroundColor = UIColor.whiteColor;
    [header addSubview:whiteView];
    whiteView.layer.cornerRadius = 4;
    whiteView.clipsToBounds = YES;
    __weak typeof(self) weakSelf =  self;
    NSString * title = @"确认成功";
    UIColor * colro = STONEOBS_UI_FIRST_TEXT_COLOR;
    NSString * imageName = @"icon_ok-02拷贝1";
    if (!self.pay_success) {
        title = @"确认失败";
       imageName = @"发布动态 删除图片";
        colro = FlatRed;
    }
    title = self.result_str;
    STTools_MenuControl * menuControl = [[STTools_MenuControl alloc] initWithFrame:CGRectMake(0, 24, 200, 100) imageName:imageName title:title titleColor:colro ];
    [menuControl setOnSelctedControl:^(STTools_MenuControl *control) {
        
    }];
    menuControl.titleLable.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:17];
    menuControl.centerX = whiteView.width / 2;
    [whiteView addSubview:menuControl];
    
    STButton * lookbutton = [[STButton alloc] initWithFrame:CGRectMake(0, whiteView.height-52, whiteView.width/2, 52)
                                                  title:@"查看订单"
                                             titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                              titleFont:18
                                           cornerRadius:0
                                        backgroundColor:WH_UICOLOR_FROM_RGBA(0xF9F9F9)
                                        backgroundImage:nil
                                                  image:nil];
//    [whiteView addSubview:lookbutton];
    lookbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [lookbutton setClicAction:^(UIButton *sender) {

        
    }];
    
    STButton * gobutton = [[STButton alloc] initWithFrame:CGRectMake(02, whiteView.height-52, whiteView.width, 52)
                                                  title:@"继续购物"
                                             titleColor:UIColor.whiteColor
                                              titleFont:18
                                           cornerRadius:0
                                        backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                        backgroundImage:nil
                                                  image:nil];
    [whiteView addSubview:gobutton];
    gobutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [gobutton setClicAction:^(UIButton *sender) {
        [weakSelf.navigationController popToRootViewControllerAnimated:YES];
    }];
    
    header.height = whiteView.bottom;
    self.tableView.tableHeaderView = header;
    
}
- (void)configWaitResultView{
    __weak typeof(self) weakSelf =  self;
    UIView * header = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    
    STTools_NoresultView * noresultView = [[STTools_NoresultView alloc] initWithFrame:CGRectMake(0, 50, UISCREEN_WIDTH, 400) title:@"正在确认收货....." buttonTitle:@"" buttonHandle:^(NSString *titleString) {
        
    }];
    header.height = noresultView.bottom;
    [header addSubview:noresultView];
    self.tableView.tableHeaderView = header;
}

#pragma mark --Action Method
- (void)send_confim_request{

    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,self.url];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumPost
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        self.result_str = [responseObject[@"message"] description];
        self.pay_success = YES;
        [self configSubView];
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        self.pay_success = NO;
        self.result_str = error.desc;
//        [SVProgressHUD showErrorWithStatus:error.desc];
        [self configSubView];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
@end
